package Infinite::Sequence::Sum;
use Exporter qw{import};

our @EXPORT_OK = qw{SUM Sum};

sub Sum { SUM(@_) }
sub SUM {
	my $sequence = pop;
    my @range = @_;
    
    die q{Summation works only in positive range} if $range[0] < 0;

    Infinite::Sequence::take( $range[0] => $sequence ) if 0 < $range[0];
    
    my @elements = Infinite::Sequence::take( scalar( @range ), $sequence );
    
    my $sum;
    $sum += $_ for @elements;
    $sum
}

1